package day4;

import org.junit.Test;

public class PointTest1 {

    @Test
    public void test01() {
        // 实例化点(0,0)
        Point p1 = new Point();
        System.out.println(p1.x + " " + p1.y);
    }

    @Test
    public void test02() {
        // 实例化点(0,0)
        Point p2 = new Point();
        p2.x = 1;
        p2.y = 2;

        // 实例化点(1,2)
        Point p3 = new Point(1, 2);
    }

    @Test
    public void test03() {
        Point p1 = new Point();  // 点(0,0)
        Point p2 = new Point(3, 4);  // 点(3,4)

        // p2到p1的距离  p2.distance(p1);
        double d = p1.distance(p2);
        System.out.println(d);

        double d2 = p2.distance(6, 8);
        System.out.println(d2);

        // p2到原点的距离
        double d3 = p2.distance();
        System.out.println(d3);
    }

    @Test
    public void testPoints() {
        // 实例化点(0,0)
        Point p1 = new Point();  // 使用无参构造器

        // 实例化点(1,2)
        Point p2 = new Point(1, 2);  // 使用有参构造器

        System.out.println("Point 1: (" + p1.x + ", " + p1.y + ")");
        System.out.println("Point 2: (" + p2.x + ", " + p2.y + ")");

        // 测试各种distance方法
        double distance1 = p1.distance(p2);  // 两点间距离
        double distance2 = p2.distance(3, 4);  // 到指定点距离
        double distance3 = p2.distance();  // 到原点距离

        System.out.println("Distance between p1 and p2: " + distance1);
        System.out.println("Distance from p2 to (3,4): " + distance2);
        System.out.println("Distance from p2 to origin: " + distance3);
    }
}
